﻿using Microsoft.AspNetCore.Mvc;
using VueShopApi.Common;
using VueShopApi.Common.Extensions;
using VueShopApi.Entities;

namespace VueShopApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ValuesController
        : ControllerBase
    //: AuthorizeController
    {
        private readonly ILogger<ValuesController> _logger;
        private readonly IFreeSql _context;

        public ValuesController(ILogger<ValuesController> logger, IFreeSql context)
        {
            _logger = logger;
            _context = context;
        }

        [HttpGet]
        public IEnumerable<string> Get([FromServices] JwtHelper jwt)
        {
            //var token = HttpContext.GetBearerToken();
            //var isValid = jwt.VerifyToken(token, out _);
            //var principal = jwt.ParseToken<ManagerPrincipal>(token);
            //var principal = HttpContext.GetClaimsPrincipal();
            return new[] { "value1", "value2" };
        }

        [HttpGet("{id}")]
        public async Task<IActionResult> Get([FromRoute] int id)
        {
            var attribute = await _context.Select<SpAttribute>(id).ToOneAsync();
            //return ServerResponse.Yes(attribute.Pick("delete_time", "attr_write"));
            return ServerResponse.Yes(attribute.Merge(new { sex = "男", age = 18 }));

            //var attributes = await _context.Select<SpAttribute>().Limit(20).ToListAsync();
            //return ServerResponse.Yes(attributes.Pick("delete_time", "attr_write"));
        }
    }
}
